package com.kim.user.web.service.impl;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.kim.user.common.entity.SysRole;
import com.kim.user.common.entity.SysRoleExample;
import com.kim.user.web.dao.SysRoleMapper;
import com.kim.user.web.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Mr.Yangxiufeng
 * Date: 2018-05-10
 * Time: 20:28
 */
@Service
@Slf4j
public class RoleServiceImpl implements RoleService {

    @Resource
    private SysRoleMapper roleMapper;

    @Override
    public List<SysRole> getRoleByUserId(Integer userId) {
        return roleMapper.getRoleByUserId(userId);
    }

    @Override
    @LcnTransaction
    @Transactional
    public int insertRole(SysRole sysRole) {
        log.info("开始执行role insert方法");
        int i = roleMapper.insertSelective(sysRole);
        i = 1 / 0;
        log.info("执行成功");
        return i;
    }

    @Override
    public SysRole findByRolename(String rolename) {
        SysRoleExample sysRoleExample = new SysRoleExample();
        SysRoleExample.Criteria criteria = sysRoleExample.createCriteria();
        criteria.andNameEqualTo(rolename);
        List<SysRole> sysRoles = roleMapper.selectByExample(sysRoleExample);
        return sysRoles != null && sysRoles.size()!=0 ?  sysRoles.get(0):null;
    }
}
